package com.example.demo.commen;

import lombok.Data;

import java.io.Serializable;

@Data
public class ResultUtil implements Serializable {
    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Integer code;
    private String message;
    private Object data;

    public ResultUtil() {

    }

    //返回成功
    public static ResultUtil success(){
        ResultUtil resultUtil=new ResultUtil();
        resultUtil.setCode(ResultCode.SUCCESS.code());
        resultUtil.setMessage(ResultCode.SUCCESS.message());
        return resultUtil;
    }

    //返回登录成功
    public static ResultUtil loginSuccess(){
        ResultUtil resultUtil=new ResultUtil();
        resultUtil.setCode(ResultCode.LOGINSUCCESS.code());
        resultUtil.setMessage(ResultCode.LOGINSUCCESS.message());
        return resultUtil;
    }

    //返回登录成功带data
    public static ResultUtil loginSuccess(Object data){
        ResultUtil resultUtil=new ResultUtil();
        resultUtil.setCode(ResultCode.LOGINSUCCESS.code());
        resultUtil.setMessage(ResultCode.LOGINSUCCESS.message());
        resultUtil.setData(data);
        return resultUtil;
    }
    
    //返回成功带data
    public static ResultUtil success(Object data){
        ResultUtil resultUtil=new ResultUtil();
        resultUtil.setCode(ResultCode.SUCCESS.code());
        resultUtil.setMessage(ResultCode.SUCCESS.message());
        resultUtil.setData(data);
        return resultUtil;
    }
    //自定义返回成功
    public static ResultUtil success(Integer code,String message,Object object){
        ResultUtil resultUtil=new ResultUtil();
        resultUtil.setCode(code);
        resultUtil.setMessage(message);
        resultUtil.setData(object);
        return resultUtil;
    }

    //返回失败
    public static ResultUtil failed(){
        ResultUtil resultUtil=new ResultUtil();
        resultUtil.setCode(ResultCode.FAILED.code());
        resultUtil.setMessage(ResultCode.FAILED.message());
        return resultUtil;
    }

    //返回登录失败
    public static ResultUtil loginFailed(){
        ResultUtil resultUtil=new ResultUtil();
        resultUtil.setCode(ResultCode.LOGINFAILED.code());
        resultUtil.setMessage(ResultCode.LOGINFAILED.message());
        return resultUtil;
    }
    
    //自定义返回失败
    public static ResultUtil failed(Integer code,String message){
        ResultUtil resultUtil=new ResultUtil();
        resultUtil.setCode(code);
        resultUtil.setMessage(message);
        resultUtil.setData(null);
        return resultUtil;
    }

    public ResultUtil(ResultCode resultCode,Object data){
        this.code = resultCode.code();
        this.message = resultCode.message();
        this.data = data;
    }

    public enum ResultCode {
        LOGINSUCCESS(200,"登录成功"),
        LOGINFAILED(500,"登录失败"),
        SUCCESS(200,"操作成功"),
        FAILED(500,"操作失败");
        private Integer code;
        private String message;

        ResultCode(Integer code, String message) {
            this.code = code;
            this.message = message;
        }

        public Integer code(){
            return this.code;
        }
        public String message(){
            return this.message;
        }

    }
}
